﻿using System;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;

namespace ElectronicWMSA.Warehouse
{
    public partial class List_VersionBaseFrm : Form
    {
        public List_VersionBaseFrm()
        {
            InitializeComponent();

            this.pageControl1.PageCurrent = 1;
            this.pageControl1.PageSize = 100;
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.pageControl1.Bind();
        }
        private string strWhere = "";
        private int DBindData_Version()
        {
            Comm.Forms.MsControls.PageData pageData = new Comm.Forms.MsControls.PageData();
            pageData.TableName = "T_Version";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.pageControl1.PageCurrent;
            pageData.PageSize = this.pageControl1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            WaitingBoxFrm wf = new WaitingBoxFrm((obj, args) => { Thread.Sleep(500); pageData.QueryDataTable(); }, 1200); wf.ShowDialog(this);

            this.pageControl1.bindingSource.DataSource = pageData.dsInfo.Tables[0];
            this.pageControl1.bindingNavigator.BindingSource = pageControl1.bindingSource;

            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = this.pageControl1.bindingSource;
            this.dataGridView1.ClearSelection();
            return pageData.TotalCount;
        }

        private int pageControl1_EventPaging(Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindData_Version();
        }
        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);

        }

        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }
        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }
        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }

        private void btn_ExportPKNOInfo_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                if (MessageClass.enquire("确认导出？") == DialogResult.OK)
                {
                    DataTable dt;
                    string SelectSQL = "SELECT [ProductModel] AS 机种,[VersionNum] AS 版本号,[StartTime] AS 开始日期 ,[EndTime] AS 结束日期,[CreatTime] AS 创建时间 FROM [DB_WMSFIRST].[dbo].[T_Version]";
                    if (strWhere != "")
                    {
                        SelectSQL += " WHERE " + strWhere + " ";
                    }
                    SelectSQL += "   ORDER BY [ProductModel] ASC ";
                    dt = SYDZ.WMS.DBUtility.DbHelperSQL.ExecuteDataTable(SelectSQL);
                    ExPut.GetNopiExcel(dt);
                }
            }
            else
            {
                MessageClass.warning("请先查询数据！");
            }
        }

        private void btnPicking_Search_Click(object sender, EventArgs e)
        {
            strWhere = " 1=1 ";
            if (!string.IsNullOrEmpty(txt_ProductModel.Text.Trim()))
            {
                this.strWhere += "   AND [ProductModel] = '" + txt_ProductModel.Text.Trim() + "' ";
            }
            this.pageControl1.Bind();
        }

       
    }
}
